{% extends "base_sub.html" %}

{% block title %}调查结果{% endblock title %}

{% block content %}
    <div id="poll_result" class="new_win">
        <h1 id="win_title">调查结果</h1>
        <div class="new_win_con2">
            <!-- 调查结果图的开始 { -->
            <span class="poll_all position-absolute d-inline-block fs-5 em-font wrapper-bg rounded-2 px-3 py-2" style="top: 10px;right: 10px;">已满 {{ total_count|number_format }}表</span>
            <section id="poll_result_list" class="m-4 main-border cont-bg rounded-2 overflow-hidden">
                <h2 class="fs-5 p-4 mb-4 text-center point-bg main-font">{{ poll.po_subject }} 结果</h2>
                <ol class="m-0 px-4">
                {% for item in items %}
                    <li class="{{ 'poll_1st' if item.rank == 1 }} my-4 position-relative list-unstyled main-font fs-5">
                        <span>{{ item.subject }}</span>
                        <div class="poll_result_graph position-relative my-2 rounded-3 input-border input-bg" style="width: 90%;height: 15px;">
                            <span class="position-absolute main-bg top-0 start-0 rounded-3" style="width:{{ item.rate }}%;height:15px;background:#8395b3;"></span>
                        </div>
                        <div class="poll_numerical d-inline-block position-absolute top-0 end-0 text-center">
                            <strong class="poll_cnt fs-5 text-end" style="color: #8d8d8d;">{{ item.count|number_format }} 表</strong>
                            <span class="poll_percent d-block fs-5 em-font fw-bold">{{ item.rate }} %</span>
                        </div>
                    </li>
                {% endfor %}
                </ol>
            </section>
            <!-- } 调查结果图结束 -->

            <!-- 开始对其他意见进行调查 { -->
            {% if poll.po_etc %}
                <section id="poll_result_cmt" class="m-4">
                    <h2 class="blind">关于本次调查的其他意见</h2>
                    {% for etc in poll.etcs %}
                        <article class="position-relative main-bb my-4 fs-5">
                            <header class="mb-2 main-font">
                                <h2 class="blind">{{ etc.pc_name }}<span>您的意见</span></h2>
                                {{ etc.pc_name }}
                                <span class="poll_datetime d-inline-block fs-5" style="color: #777;">{{ etc.pc_datetime|safe }}</span>
                                {% if etc.mb_id == request.state.login_member.mb_id or request.state.login_member.mb_level == 10 %}
                                    <span class="poll_cmt_del d-inline-block">
                                        <a href="{{ url_for('poll_etc_delete', po_id=etc.po_id, pc_id=etc.pc_id) }}" class="poll_delete d-inline-block mb-2 ms-3 fs-5" style="color: #c7c9cb;" onclick="del(this.href); return false;">
                                            <i class="fa fa-circle-xmark" aria-hidden="true"></i>
                                            <span class="blind">删除</span>
                                        </a>
                                    </span>
                                {% endif %}
                            </header>
                            <p class="py-3 main-font">{{ etc.pc_idea[:255]|safe }}</p>
                        </article>
                    {% endfor %}
                    {% if get_member_level(request) >= poll.po_level %}
                        <form name="fpollresult" action="{{ url_for('poll_etc_update', po_id=poll.po_id) }}" onsubmit="return fpollresult_submit(this);" method="post" autocomplete="off" id="poll_other_q" class="m-0 fs-5 main-font text-start">
                            <input type="hidden" name="token" value="">
                            {% if request.state.login_member.mb_id %}
                                <input type="hidden" name="pc_name" value="{{ request.state.login_member.mb_nick }}">
                            {% endif %}
                            <div id="poll_result_wcmt" class="innput-border mb-3">
                                <h3 class="m-0 p-3 main-border border-bottom-0 fw-bold"><span class="p-2 d-inline-block rounded-2 me-2 fw-normal fs-5" style="background:#f7f8e3;color:#c97600;">其他意见</span>{{ poll.po_etc|safe }}</h3>
                                <div>
                                    <label for="pc_idea" class="blind">意见<strong>必不可少的</strong></label>
                                    <input type="text" id="pc_idea" class="w-100 bg-transparent main-font main-border p-3" style="height: 80px;" name="pc_idea" required="" class="full_input required" size="47" maxlength="100" placeholder="请输入您的意见">
                                </div>
                            </div>
                            {% if not request.state.login_member.mb_id %}
                                <div class="poll_guest">
                                    <label for="pc_name" class="blind">姓名<strong>必不可少的</strong></label>
                                    <input type="text" name="pc_name" id="pc_name" required="" class="full_input required main-border p-3 mb-3 d-inline-block input-bg main-border main-font" size="20" placeholder="姓名">
                                </div>
                                <!-- Captcha Start -->
                                <fieldset id="captcha" class="captcha">
                                    {% include captcha_widget(request) ignore missing %}
                                </fieldset>
                                <!-- Captcha End -->
                            {% endif %}
                            <button type="submit" class="btn_submit p-4 d-flex ms-auto">发表评论</button>
                        </form>
                    {% endif %}
                </section>
            {% endif %}
            <!-- } 调查结束其他意见 -->
    
            <!-- 开始查看调查的其他结果 { -->
            <aside id="poll_result_oth" class="m-4">
                <h2 class="main-font pb-4 fs-5 fw-bold">查看其他调查结果</h2>
                <ul class="list-unstyled main-border cont-bg">
                    {% for other in other_list %}
                        <li class="position-relative main-bt py-2">
                            <a href="{{ url_for('poll_result', po_id=other.po_id) }}" class="d-block p-3">{{ other.po_subject }}</a>
                            <span class="position-absolute fs-5" style="bottom: 10px;right: 15px;color: #777">
                                <i class="fa fa-regular fa-clock" aria-hidden="true"></i>
                                {{ other.po_date }}
                            </span>
                        </li>
                    {% endfor %}
                </ul>
            </aside>
            <!-- } 调查结束查看其他结果 -->
            <div class="text-center">
                <button type="button" onclick="window.close();" class="btn_close fs-5">窗口关闭</button>
            </div>
        </div>
    </div>
    
    <script>    
    function fpollresult_submit(f)
    {
        f.token.value = generate_token();
        if (f.token.value == "") {
            alert("创建令牌失败.");
            return false;
        }
        // captcha 使用时
        if (typeof check_captcha === "function") {
            if (!check_captcha(f)) {
                return false;
            }
        }

        return true;
    }
    
    </script>
{% endblock content %}